﻿using System;
using System.Net;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //ShieldGenerators
    public class ShieldGenerator : StarShip
    {
        //constructor
        public ShieldGenerator(SVGame game, Player owner, int engines, StarSystem origin)
            : base(game, owner, engines, 0, origin)
        {
        }

        //Name
        public override string Name
        {
            get
            {
                return "ShieldGenerator";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "ShieldsGenerators can generate Shields around StarSystems.  The generation rate is based on the Engine rating of the ShieldGenerator.";
            }
        }

        //ship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.ShieldGenerator;
            }
        }

        //can target any starsystem
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.TargetStarSystem:
                    return true;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }
        public override bool CanTargetStarSystem(StarSystem target, bool considerAlliance)
        {
            return true;
        }

        //private members
        private int _count = 0;

        //when next to target, generate shields
        protected override void TargetAdjacentStarSystem(StarSystem system)
        {
            _count++;
            if (_count > Math.Abs(system.Shields))
            {
                _count = 0;
                system.Shields++;
                Game.SubmitStateChange(StateChange.SetShields, system, system.Shields);
            }
        }
    }
}
